<template>
  <div class="ruralMonitoringBox">
    <div class="title">县乡村监控数量统计</div>

    <div style="height: 100%" ref="RuralMonitoring" id="RuralMonitoring" class="charts"></div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import { getEchartsZoomEnd, getEchartsXAxisLabel } from '@/utils/util'
export default {
  name: 'Ruralmonitoring',
  data() {
    return {}
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      const myChart = echarts.init(document.getElementById('RuralMonitoring'))
      let xdata = ['新城街道', '东城街道', '老街街道', '黄寨镇', '练集镇', '魏集镇']
      let seriesData = [2589, 655, 509, 368, 310, 304]
      const { zoomShow, zoomEnd } = getEchartsZoomEnd(xdata, 7)
      let option = {
        grid: {
          top: '32',
          bottom: '24',
          left: '16',
          right: '16',
          containLabel: true,
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow',
          },
          backgroundColor: 'rgba(0,0,0,0.5)',
          borderColor: 'rgba(0,0,0,0)',
          textStyle: {
            color: '#ffffff',
          },
        },
        dataZoom: {
          show: zoomShow,
          type: 'slider',
          realtime: true,
          height: 5,
          start: 0,
          end: zoomEnd,
          textStyle: false,
          zoomLock: true,
          bottom: 10,
          handleSize: 0,
          fillerColor: 'rgba(44, 74, 130, 1)',
          backgroundColor: 'rgba(0, 0, 0, 0)',
          borderColor: 'rgba(0, 0, 0, 0)',
          showDataShadow: false,
          showDetail: false,
          brushSelect: false,
          filterMode: 'empty',
        },
        xAxis: [
          {
            type: 'category',
            IsStaggered: '',
            data: xdata,
            axisLine: {
              show: true,
              lineStyle: {
                color: 'rgba(255, 255, 255, 0.2)',
                width: 1,
                type: 'solid',
              },
            },
            axisTick: {
              show: false,
            },
            axisLabel: {
              show: true,
              textStyle: {
                color: '#ffffff',
              },
              interval: 0,
              formatter: label => {
                return getEchartsXAxisLabel(label)
              },
            },
            splitLine: {
              show: false,
            },
          },
        ],
        yAxis: {
          show: true,
          type: 'value',
          name: '单位:万人',
          axisLabel: {
            textStyle: {
              color: '#ffffff',
            },
          },
          axisTick: {
            show: false,
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: 'rgba(255, 255, 255, 0.2)',
              width: 1,
              type: 'solid',
            },
          },
          splitLine: {
            show: false,
          },
        },
        series: [
          {
            name: '',
            type: 'bar',
            data: seriesData,
            barWidth: 10,
            itemStyle: {
              barBorderRadius: 50,
              color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
                { offset: 0, color: '#6F7BE9' },
                { offset: 1, color: '#44C5F5 ' },
              ]),
            },
          },
        ],
      }
      myChart.setOption(option)
    },
  },
}
</script>

<style lang="less" scoped>
.ruralMonitoringBox {
  width: 340px;
  height: 265px;
  background-image: url('@/assets/community/boxbg3.png');
  background-repeat: no-repeat;
  background-size: 100% 100%;
  display: flex;
  flex-direction: column;

  .title {
    margin-top: 8px;
    width: 100%;
    height: 20px;
    font-size: 14px;
    color: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .charts {
    flex: 1;
  }
}
</style>
